package com.ra.controller;


import com.ra.pojo.Resource;
import com.ra.pojo.RespBean;
import com.ra.pojo.dto.ConditionDTO;
import com.ra.pojo.dto.LabelOptionDTO;
import com.ra.pojo.dto.ResourceDTO;
import com.ra.pojo.dto.ResourceDTOByAdmin;
import com.ra.service.IResourceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 今晚几点睡_Ada
 * @since 2023-03-09
 */
@RestController
@Api(tags = "接口管理模块")
public class ResourceController {
    @Autowired
    private IResourceService resourceService;

    @GetMapping("admin/resources")
    @ApiOperation(value = "查询资源列表")
    public RespBean<List<ResourceDTO>>listResource(ConditionDTO conditionDTO){
        return RespBean.success(resourceService.listResource(conditionDTO));
    }
    @PostMapping("admin/resources")
    @ApiOperation("新增或修改资源")
    public RespBean<?> saveOrUpdateResource(@RequestBody @Valid ResourceDTOByAdmin resource){
        resourceService.saveOrUpdateResource(resource);
        return RespBean.success();
    }
    @DeleteMapping("admin/resources/{id}")
    @ApiOperation("删除资源")
    public RespBean<?> delResource(@PathVariable("id") Integer id){
       resourceService.delResource(id);
        return RespBean.success();
    }
    @GetMapping("admin/role/resources")
    @ApiOperation("获取角色资源")
    public RespBean<List<LabelOptionDTO>> queryRoleResources(){
        return RespBean.success(resourceService.queryRoleResources());
    }





}

